package xyz.zdsoft.ask_for_leave_manage_module.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import xyz.zdsoft.ask_for_leave_manage_module.bo.AdminStudentLeaveRecordsBo;
import xyz.zdsoft.ask_for_leave_manage_module.mapper.AdminLeavesMapper;
import xyz.zdsoft.ask_for_leave_manage_module.service.AdminLeavesService;
import xyz.zdsoft.ask_for_leave_manage_module.vo.AdminStudentLeaveRecordsVo;
import xyz.zdsoft.ask_for_leave_manage_module.vo.AdminStudentLeavesDetailsVo;
import xyz.zdsoft.common.entity.Attachement;
import xyz.zdsoft.common.entity.LeaveOperationRecord;
import xyz.zdsoft.common.service.impl.AttachementServiceImpl;
import xyz.zdsoft.common.service.impl.LeaveOperationRecordServiceImpl;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 管理员-请假记录业务逻辑处理接口实现类
 * @author 以风
 */
@Service
public class AdminLeavesServiceImpl implements AdminLeavesService {
    @Resource
    private AdminLeavesMapper adminLeavesMapper;

    @Resource
    private LeaveOperationRecordServiceImpl leaveOperationRecordService;

    @Resource
    private AttachementServiceImpl attachementService;

    /**
     * 获取学生请假记录分页信息列表（查询、分页、重置）a
     *
     * @param page                       分页参数
     * @param adminStudentLeaveRecordsBo 学生请假记录入参
     * @return 学生请假记录分页信息列表
     */
    @Override
    public IPage<AdminStudentLeaveRecordsVo> getStudentLeaveRecordsPage(IPage<AdminStudentLeaveRecordsVo> page, AdminStudentLeaveRecordsBo adminStudentLeaveRecordsBo) {
        IPage<AdminStudentLeaveRecordsVo> adminStudentLeaveRecordsVoIPage = adminLeavesMapper.getStudentLeaveRecordsPage(page,adminStudentLeaveRecordsBo);
        return adminStudentLeaveRecordsVoIPage;
    }

    /**
     * 获取学生请假详情
     *
     * @param leaveId 请假id
     * @return 请假详情
     */
    public Map<String,Object> getStudentLeaveDetails(Integer leaveId) {
        //获取请假附件相关信息
        QueryWrapper<Attachement> wrapper = new QueryWrapper<>();
        wrapper.eq("origin_id",leaveId)
                .eq("origin_type","2");
        List<Attachement> attachementList = attachementService.list(wrapper);

        //获取请假记录相关信息
        List<AdminStudentLeavesDetailsVo> leavesDetailsVos = adminLeavesMapper.getStudentLeaveDetails(leaveId);
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("attachementList",attachementList);
        resultMap.put("leavesDetailsVos",leavesDetailsVos);

        return resultMap;
    }

}
